package com.wyu.blog.service;


import com.wyu.blog.dao.ArticleMapper;
import com.wyu.blog.entity.Article;
import com.wyu.blog.entity.Category;
import com.wyu.blog.entity.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    /**
     * 根据用户ID查询所有文章
     * @param userId
     * @return
     */
    public List<Article> findArticleByUserId(Integer userId) {
        return articleMapper.selectArticleByUserId(userId);
    }

    /**
     * 查询所有文章
     * @return
     */
    public List<Article> findAllArticle() {
        return articleMapper.selectAllArticle();
    }

    /**
     * 模糊查询文章
     * @param articleTitle
     * @return
     */
    public List<Article> findArticleByLike(String articleTitle){
        return articleMapper.selectArticleByLike(articleTitle);
    }

    /**
     * 模糊查询文章数
     * @param articleTitle
     * @return
     */
    public Integer findArticleNumByLike(String articleTitle){
        return articleMapper.selectArticleNumByLike(articleTitle);
    }

    /**
     * 根据文章ID查询文章
     * @return
     */
    public Article findArticleById(Integer articleId) {
        return articleMapper.selectArticleById(articleId);
    }

    /**
     * 根据文章ID查询文章
     * @return
     */
    public Article findArticleByTitle(String articleTitle) {
        return articleMapper.selectArticleByTitle(articleTitle);
    }

    /**
     * 根据文章ID和分类ID查询文章
     * @return
     */
    public List<Article> findArticle(HashMap map) {
        return articleMapper.selectArticle(map);
    }

    /**
     * 根据文章ID和分类ID查询文章数
     * @return
     */
    public Integer findArticleSortNum(HashMap map) {
        return articleMapper.selectArticleSortNum(map);
    }


    /**
     * 查询最新文章
     * @return
     */
    public List<Article> findRecentArticle(){
        return articleMapper.selectRecentArticle();
    }

    /**
     * 查询热门文章
     * @return
     */
    public List<Article> findHotArticle(){
        return articleMapper.selectHotArticle();
    }

    /**
     * 查询置顶文章
     * @return
     */
    public List<Article> findTopArticle(){
        return articleMapper.selectTopArticle();
    }

    /**
     * 查询个人文章总数
     * @param userId
     * @return
     */
    public Integer findArticleNum(Integer userId) {
        return articleMapper.selectArticleNum(userId);
    }

    /**
     * 保存博客
     * @param article
     */
    public void saveArticle(Article article){
        articleMapper.insertArticle(article);
    }

    /**
     * 根据id删除文章信息
     * @param articleId
     * @return
     */
    public Integer deleteArticle(Integer articleId) {
        return articleMapper.deleteArticleById(articleId);
    }





    /**
     * 查询个人文章分类
     * @param userId
     * @return
     */
    public List<Sort> findSortById(Integer userId) {
        return articleMapper.selectSortById(userId);
    }

    /**
     * 查询个人文章分类总数
     * @param userId
     * @return
     */
    public Integer findSortNum(Integer userId) {
        return articleMapper.selectSortNum(userId);
    }

    /**
     * 查询每个用户的文章分类信息
     * @param userId
     * @return
     */
    public List<Category> findCategoryById(Integer userId) {
        return articleMapper.selectCategoryById(userId);
    }

    /**
     * 查询所有文章分类的信息
     * @return
     */
    public List<Category> findAllCategory() {
        return articleMapper.selectAllCategory();
    }

    /**
     * 根据分类ID查询文章信息
     * @param sortId
     * @return
     */
    public List<Article> findArticleBySortId(Integer sortId) {
        return articleMapper.selectArticleBySortId(sortId);
    }

    /**
     * 根据ID查询分类信息
     * @param sortId
     * @return
     */
    public Category findCategoryBySortId(Integer sortId) {
        return articleMapper.selectCategoryBySortId(sortId);
    }


    /**
     * 根据ID修改文章信息(后台)
     * @param article
     */
    public Integer updateArticleById(Article article) {
        return articleMapper.updateArticleById(article);
    }

    /**
     * 根据ID修改文章信息(前台)
     * @param article
     */
    public Integer updateArticle(Article article) {
        return articleMapper.updateArticle(article);
    }


    /**
     * 修改浏览量
     * @param article
     */
    public Integer updateView(Article article) {
        return articleMapper.updateViewNum(article);
    }

    /**
     * 修改收藏量
     * @param article
     */
    public Integer updateCollect(Article article) {
        return articleMapper.updateCollectNum(article);
    }

    /**
     * 修改评论量
     * @param article
     */
    public Integer updateComment(Article article) {
        return articleMapper.updateCommentNum(article);
    }


}
